package com.my.biao.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.my.biao.R;

/**
 * 项目名称：通用Dialog
 * 创建人：mwb
 * 创建时间：2018/10/22 11:13
 */
public class DialogComment extends Dialog {
    private TextView tvTitle; // 标题
    private TextView tvMessage; // 内容
    private TextView tvSure; // 确定
    private TextView tvCancel; // 取消
    private OnDialogBtnClickListener onDialogListener;

    private String title;
    private String message;

    public DialogComment(@NonNull Context context, OnDialogBtnClickListener onDialogBtnClickListener) {
        super(context, R.style.MySimpleDialog);
        this.onDialogListener = onDialogBtnClickListener;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_common_simple);
        this.setCanceledOnTouchOutside(false);
        initView();
        initListener();
    }

    private void initView() {
        tvTitle = findViewById(R.id.dialog_common_title_tv);
        tvMessage = findViewById(R.id.dialog_message_common_tv);
        tvCancel = findViewById(R.id.dialog_common_cancel_tv);
        tvSure = findViewById(R.id.dialog_common_sure_tv);

        if (title != null) {
            tvTitle.setText(title);
        }

        if (message != null) {
            tvMessage.setText(message);
        }
    }

    private void initListener() {
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDialogListener.onCancle();// 取消
            }
        });

        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDialogListener.onSure();// 确定
            }
        });
    }

    public interface OnDialogBtnClickListener {
        void onSure();

        void onCancle();
    }
}
